#include "System.h"
#include "Game_State.h"
#include "StateMachine.h"
#include <stdio.h>
#include <Windows.h>

//	Begin game with state GS_INTRO
System::System()
{
	m_pStateMachine = new StateMachine<System>(System::Instance());
	m_pStateMachine->SetCurrentState(Intro::Instance());
	GameState = GS_INTRO;
}

//	Return the only system instance
System* System::Instance()
{
	static System instance;
	return &instance;
}

//	Change the game to another state
//	State are declared in "Game_State.h"
void System::ChangeState(State<System>* newState)
{
	m_pStateMachine->ChangeState(newState);
}

//	Go back to previous state
void System::PreviousState()
{
	m_pStateMachine->RevertToPreviousState();
}

//	Execute current state
void System::Update()
{
	m_pStateMachine->Update();
}

//	Return true if current/next state is matched
bool System::IsState(int state)
{
	return state == GameState;
}

//	Set the state
void System::SetState(int state)
{
	GameState = state;
}

//	Return true if exit game
bool System::Exit()
{
	return Exit;
}

//	Show Intro of the game
void System::DoIntro()
{
	printf("This is Intro run by System\n");
	Sleep(500);
	GameState = GS_MAIN_MENU;
}

//	View Mainmenu and selecting
void System::DoMainMenu()
{
	int chooseWhat = 0;
	printf("System Game\n1) NewGame\n2)ExitGame\nChoose: ");
//	choose = chooseWhat;
}

//	Create a new game profile
void System::DoNewGame()
{
	printf("New game is created\nCount to zero:");
	for(int i=9;i>=0;i--)
	{
		printf(" %d -",i);
		Sleep(100);
	}
	printf("\nYou won\n");
}

//	Exit Game
void System::DoExitGame()
{
	printf("Press anykey to exit\n");
	getchar();
	exit(0);
}